package cn.itcast.nems.studentrecord.web.controller.b;

import cn.itcast.nems.studentrecord.bo.StudentRecordInvoiceBo;
import cn.itcast.nems.studentrecord.service.StudentRecordInvoiceService;
import cn.itcast.nems.studentrecord.vo.StudentRecordInvoiceVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/b/student")
@RequiredArgsConstructor
@Slf4j
public class StudentRecordInvoiceController {

    private final StudentRecordInvoiceService studentRecordInvoiceService;

    @GetMapping("/{studentId}/record/{studentRecordId}/invoices")
    public ResponseEntity<List<StudentRecordInvoiceVo>> listStudentRecordInvoices(
            @PathVariable("studentId") Integer studentId,
            @PathVariable("studentRecordId") String studentRecordId
    ) {
        return ResponseEntity.ok(studentRecordInvoiceService.listStudentRecordInvoices(
                studentId, studentRecordId
        ));
    }

    @PostMapping("/{studentId}/record/{studentRecordId}/invoices")
    public ResponseEntity<Boolean> createStudentRecordInvoice(
            @PathVariable("studentId") Integer studentId,
            @PathVariable("studentRecordId") String studentRecordId,
            @RequestBody StudentRecordInvoiceBo studentRecordInvoiceBo
    ) {
        return ResponseEntity.ok(studentRecordInvoiceService.createStudentRecordInvoice(
                studentId,
                studentRecordId,
                studentRecordInvoiceBo
        ));
    }

    @PutMapping("/{studentId}/record/{studentRecordId}/invoices/{invoiceId}")
    public ResponseEntity<Boolean> updateStudentRecordInvoice(
            @PathVariable("studentId") Integer studentId,
            @PathVariable("studentRecordId") String studentRecordId,
            @PathVariable("invoiceId") String invoiceId,
            @RequestBody StudentRecordInvoiceBo studentRecordInvoiceBo
    ) {
        return ResponseEntity.ok(studentRecordInvoiceService.updateStudentRecordInvoice(
                studentId,
                studentRecordId,
                invoiceId,
                studentRecordInvoiceBo
        ));
    }

    @DeleteMapping("/{studentId}/record/{studentRecordId}/invoices/{invoiceId}")
    public ResponseEntity<Boolean> deleteStudentRecordInvoice(
            @PathVariable("studentId") Integer studentId,
            @PathVariable("studentRecordId") String studentRecordId,
            @PathVariable("invoiceId") String invoiceId
    ) {
        return ResponseEntity.ok(studentRecordInvoiceService.deleteStudentRecordInvoice(
                studentId,
                studentRecordId,
                invoiceId
        ));
    }

}
